<!--
 * @Descripttion: unTitle
 * @Author: yizheng.yuan
 * @Date: 2021-11-02 16:51:28
 * @LastEditors: yizheng.yuan
 * @LastEditTime: 2021-11-02 17:31:25
-->
<div id="recMessage">
  Hello World!
  </div>
  <script>
  window.onload = function() {

    // 给父页面发信息
    console.log('window',window);
    window.parent.postMessage("儿子发来的信息：Hello")

    var messageEle = document.getElementById('recMessage');
    window.addEventListener('message', function (e) {  // 监听 message 事件
        alert(e.origin);
        console.error('e',e, e.origin);
        if (e.origin !== "http://localhost:8080") {  // 验证消息来源地址
            return;
        }
        messageEle.innerHTML = "从"+ e.origin +"收到消息： " + e.data;
    });
  }
  </script>